<?php
include_once 'MY/extra_sql.php';
include_once 'MY/lib_splitword_full.php';
function merger($arr,$data) {
    $array=array('0'=>'0');
    $j=count($data);
    for($i=0;$i<$j;$i++) {
        if(!in_array($data[$i],$arr)) {
            $array[].=$data[$i];
        }
    }
    return $array;
}
function GetID($prefix) {
	//第一步:初始化种子
	//microtime(); 是个数组
	$seedstr =split(" ",microtime(),5);
	$seed =$seedstr[0]*10000;
	//第二步:使用种子初始化随机数发生器
	srand($seed);
	//第三步:生成指定范围内的随机数
	$random =rand(1000,10000);

	$filename = date("Ymd", time()).$random.$prefix;

	return $filename;
}

class ProjectController extends Zend_Controller_Action{
	function init(){
		if($_SESSION['user']==""){
			 echo "<script>window.location='../user/login';</script>";exit;
		}
		$this->registry = Zend_Registry::getInstance();
		$this->view = $this->registry['view'];
		$this->view->baseUrl = $this->_request->getBaseUrl();
        $this->view->template = "project";
		$this->view->conf = new Zend_Config(require './application/configs/config.php');

		$group_id = $_SESSION['user']['group_id'];
		$group = new Group();
		$group = $group->getgroupByid($group_id);
		$groups = explode(',',$group[0]['models']);
		if(!in_array('project',$groups)){
			echo "<script>alert('No Permission To Enter!');history.go('-1');</script>";exit();
		}
	}

	public function indexAction(){
		$project = new Project();
              
		$projects = $project->getAllProjects('','');
		
		$this->view->total = count($projects);
		$this->view->top = $project->getTopProjects();
		
		//项目统计
		$filter = new Zend_Filter_StripTags();
		$project = new Project();
		$arrDate = getdate();
		$year = $arrDate['year']+1;
		$time = strtotime($year.'-01-01');
		$arrTime = array();
		for ($i=0;$i<8;$i++) {
			$arrTime[] = array(strtotime(($year-1).'-01-01'), strtotime(($year).'-01-01'));
			$year--;
			$arrYear[] = $year;
			$arrProjectType[] = array(0,0,0,0);
			$arrProjectIncome[] = array(0,0,0,0,0,0);
			$arrProjectKind[] = array(0,0,0);
		}
		foreach($arrYear as $row){
			$arrYearShow[] = strval($row);
		}
		$arrProject = array();
		foreach($arrTime as $key=>$row){
			$arrProject = $project->getProjectByTime($row[0] ,$row[1]);

			foreach($arrProject as $k=>$v){
				$arrProjectType[$key][$arrProject[$k]['category']]++;
				$arrProjectIncome[$key][$arrProject[$k]['category']]+=$v['income'];
				$arrProjectKind[$key][$arrProject[$k]['kind']]++;
			}
			$arrProjectType[$key]['year'] = $arrYear[$key];
			$arrProjectIncome[$key]['year'] = $arrYear[$key];
			$arrProjectKind[$key]['year'] = $arrYear[$key];
		}
		$cc = array();
	    foreach ($arrProjectType as $k=>$v){
	    	$j=0;
	    	for($i=0;$i<count($v);$i++){
	    	  $cc[$i]+=$v[$i];	
	    	}	    	
	    }
	    $cc['year'] = '小结';
        $arrProjectType[] = $cc;
        $c = array();
	    foreach ($arrProjectIncome as $k=>$v){
	    	for($i=0;$i<count($v);$i++){
	    	  $c[$i]+=$v[$i];	
	    	}	    	
	    }
	    $c['year'] = '小结';
        $arrProjectIncome[] = $c;
        
        $kk = array();
	    foreach ($arrProjectKind as $k=>$v){
	    	for($i=0;$i<count($v);$i++){
	    	  $kk[$i]+=$v[$i];	
	    	}	    	
	    }
	    $kk['year'] = '小结';
        $arrProjectKind[] = $kk;

		$this->view->arrProjectType = $arrProjectType;
		$this->view->arrProjectIncome = $arrProjectIncome;
		$this->view->arrProjectKind = $arrProjectKind;
		
		//项目标签
		$tag = new Tag();
		$projecttag = new ProjectTag();
		$arrProjectTag = $projecttag->getProjectTag();
		$arrTag = array();
		foreach($arrProjectTag as $row){
			if (!array_key_exists($row['tag_id'], $arrTag)) {
				$arrTag[$row['tag_id']]['tag_id'] = $row['tag_id'];
				$arrTag[$row['tag_id']]['num'] = 1;
				$arrTagId[] = $row['tag_id'];
			}else{
				$arrTag[$row['tag_id']]['num']++;
			}
		}
		if (!empty($arrTagId)) {
			$tags = $tag->getAllTagInArray($arrTagId);
			foreach($tags as $row){
				$arrTag[$row['tag_id']]['tag_name'] = $row['name'];
			}
		}
		$this->view->tags = $arrTag;
		
		echo $this->view->render('project/index.html');
	}
	
	//分词方法
	public function splitAction(){
		$filter=new Zend_Filter_StripTags();
		$str=$filter->filter($this->_request->getPost('title'));
		$sp = new SplitWord();
		$str = iconv('utf-8','gb2312',$str);
		$str = $sp->SplitRMM($str);
		$str = iconv('gb2312','utf-8',$str);
		echo $str;
		$sp->Clear();
	}
	
	//添加项目方法
	public function addAction(){
		$filter=new Zend_Filter_StripTags();
		$project = new Project();
		$operation = new Operation();
		$class = new Classes();
		if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
			$teacher_id=$filter->filter(($this->_request->getPost('teacher_id')));
			$class_id=$filter->filter(($this->_request->getPost('class_id')));
			$student_id=$filter->filter(($this->_request->getPost('student_id')));
			$title=$filter->filter(($this->_request->getPost('title')));
			$summary=$this->_request->getPost('summary');
			$start_time=$filter->filter(($this->_request->getPost('start_time')));
			$end_time=$filter->filter(($this->_request->getPost('end_time')));
			$pid=$filter->filter(($this->_request->getPost('pid')));
			$category=$filter->filter(($this->_request->getPost('category')));
			$kind=$filter->filter(($this->_request->getPost('kind')));
			$income=$filter->filter(($this->_request->getPost('income')));
			$key=$this->_request->getPost('key_word');
			$user_id=$_SESSION['user']['user_id'];

			$create_time = time();
			$update_time = time();
			$start_time = strtotime($start_time);
			if($start_time==""){
				$cla = $class->getclassByclass_id($class_id);
				$start_time = $cla[0]['start_time'];
			}
			$data = array(
				'teacher_id'=>$teacher_id,
				'class_id'=>$class_id,
				'student_id'=>$student_id,
				'title'=>$title,
				'create_time'=>$create_time,
				'update_time'=>$update_time,
				'summary'=>$summary,
				'start_time'=>$start_time,
				'pid'=>$pid,
				'category'=>$category,
				'kind'=>$kind,
				'income'=>$income,
				'key_word'=>$key,
				'user_id'=>$user_id,
			);

			$project_id = $project->insert($data);
			if($project_id){
				$time = time();
				$data = array(
					'op_name'=>'add',
					'model_name'=>'project',
					'user_id'=>$_SESSION['user']['user_id'],
					'user_name'=>$_SESSION['user']['user_name'],
					'name'=>'增加项目',
					'create_time'=>$time
				);
				$query = $operation->insert($data);
				echo "<script>window.location='detail?project_id=".$project_id."'</script>";
			}else{
				
			}
		}
		echo $this->view->render('project/add.html');
	}

	//修改项目方法
	public function editAction(){
		$filter=new Zend_Filter_StripTags();
		$project = new Project();
		$teacher = new Teacher();
		$student = new Student();
		$class = new Classes();
		$operation = new Operation();
		$project_id=$filter->filter(($this->_request->getParam('project_id')));
	    
		if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
			$teacher_id=$filter->filter(($this->_request->getPost('teacher_id')));
			$class_id=$filter->filter(($this->_request->getPost('class_id')));
			$student_id=$filter->filter(($this->_request->getPost('student_id')));
			$title=$filter->filter(($this->_request->getPost('title')));
			$summary=$this->_request->getPost('summary');
			$start_time=$filter->filter(($this->_request->getPost('start_time')));
			$end_time=$filter->filter(($this->_request->getPost('end_time')));
			$pid=$filter->filter(($this->_request->getPost('pid')));
			$category=$filter->filter(($this->_request->getPost('category')));
			$kind=$filter->filter(($this->_request->getPost('kind')));
			$income=$filter->filter(($this->_request->getPost('income')));
			$key=$this->_request->getPost('key_word');
			$user_id=$filter->filter(($this->_request->getPost('user_id')));
			
			$update_time = time();
			$start_time = strtotime($start_time);
			$data = array(
				'teacher_id'=>$teacher_id,
				'class_id'=>$class_id,
				'student_id'=>$student_id,
				'title'=>$title,
				'update_time'=>$update_time,
				'summary'=>$summary,
				'start_time'=>$start_time,
				'pid'=>$pid,
				'category'=>$category,
				'kind'=>$kind,
				'income'=>$income,
				'key_word'=>$key,
				'user_id'=>$user_id,
			);

			$project->updateprojectByproject_id($data, $project_id);
			$time = time();
			$data = array(
				'op_name'=>'edit',
				'model_name'=>'project',
				'user_id'=>$_SESSION['user']['user_id'],
				'user_name'=>$_SESSION['user']['user_name'],
				'name'=>'修改项目',
				'create_time'=>$time
			);
			$query = $operation->insert($data);
			echo "<script>window.location='detail?project_id=".$project_id."'</script>";
		}else{
			$this->view->project= $project->getprojectByproject_id($project_id);
			$teacher_id = $this->view->project[0]['teacher_id'];
			$student_id = $this->view->project[0]['student_id'];
			$class_id = $this->view->project[0]['class_id'];

			$teacher = $teacher->getteacherByteacher_id($teacher_id);
			if(count($teacher)=='0'){
				$this->view->teacher_name = '';
			}else{
				$this->view->teacher_name = $teacher[0]['name'];
			}
	
			$student = $student->getStudentBystudent_id($student_id);
			if(count($student)=='0'){
				 $this->view->student_name = '';
			}else{
				 $this->view->student_name = $student[0]['name'];
			}
	
			$class = $class->getclassByclass_id($class_id);
			if(count($class)=='0'){
				$this->view->class_name = '';
			}else{
				$this->view->class_name = $class[0]['name'];
			}
		}
		echo $this->view->render('project/edit.html');
	}


	//项目列表页
	public function listAction(){
		$filter=new Zend_Filter_StripTags();
		$project = new Project();
		$operation = new Operation();
        $student = new Student();
        $classes = new Classes();
		$db = new mysql(constant('dbhost'),constant('dbuser'),constant('dbpass'),constant('dbname'),"UTF8");
		$page=$filter->filter(($this->_request->getParam('page')));
		$teacher_name=$filter->filter(($this->_request->getParam('teacher_name')));
		$student_name=$filter->filter(($this->_request->getParam('student_name')));
		$search_name=$filter->filter(($this->_request->getParam('search_name')));
		$search_key_words=$filter->filter(($this->_request->getParam('search_key_words')));
		$search_summary=$filter->filter(($this->_request->getParam('search_summary')));
		$search_class=$filter->filter(($this->_request->getParam('search_class')));
	    $this->view->search_name = $search_name;
		$this->view->search_key_words = $search_key_words;
		$this->view->search_summary = $search_summary;
		$this->view->search_class = $search_class;
		
		$classess = $classes->getclasslikeclass_name($search_class);
		if($search_class==""){
			$classess = array();
		}
		if($page==""){
			$page="1";
		}
		$teacher_id="";
		$student_id="";
		if($teacher_name!=""){
			$teacher = new Teacher();
			$teachers = $teacher->getteacherLikename($teacher_name);
			$teacher_id = $teachers[0]['teacher_id'];
		}else if($student_name!=""){
			$student = new Student();
			$students = $student->getstudentLikename($student_name);
			$student_id = $students[0]['student_id'];
		}
		$count = $db->select_projects('','','','',$search_name,$search_key_words,$search_summary,$classess);
		//总条数
		$total = count($count);
		//总页数
		$perpage = "10";
		$pages = ceil($total/$perpage);
		$start = ($page-1)*$perpage;
		$end = $perpage;
	
		$this->view->projects = $db->select_projects($start,$end,$teacher_id,$student_id,$search_name,$search_key_words,$search_summary,$classess);
		$this->view->page = $page;
		$this->view->pages = $pages;
		$this->view->total = $total;
		$time = time();
		$data = array(
			'op_name'=>'list',
			'model_name'=>'project',
			'user_id'=>$_SESSION['user']['user_id'],
			'user_name'=>$_SESSION['user']['user_name'],
			'name'=>'取得所有项目',
			'create_time'=>$time
		);
		$query = $operation->insert($data);
	    $this->view->students = $student->getAllStudents('','','');
		echo $this->view->render('project/list.html');
	}

	//项目详情页
	public function detailAction(){
		$filter=new Zend_Filter_StripTags();
		$project = new Project();
		$teacher = new Teacher();
		$student = new Student();
		$class = new Classes();
		$projectfile = new Projectfile();
		$projectcase = new Projectcase();
		$operation = new Operation();
		$projecttag = new ProjectTag();
		$tag = new Tag();
		$db = new mysql(constant('dbhost'),constant('dbuser'),constant('dbpass'),constant('dbname'),"UTF8");
		$project_id=$filter->filter(($this->_request->getParam('project_id')));
		$page=$filter->filter(($this->_request->getParam('page')));
		$pro_page=$filter->filter(($this->_request->getParam('pro_page')));
		$ps_page=$filter->filter(($this->_request->getParam('ps_page')));
		//comment的页数
		if($page==""){
			$page="1";
		}
	    if ($pro_page=="") {
			$pro_page="1";
		}
    	if ($ps_page=="") {
			$ps_page="1";
		}
	
		$this->view->projectfiles = $projectfile->getprojectfileByproject_id($project_id);
		$this->view->projectcases = $projectcase->getprojectcaseByproject_id($project_id);
//		echo '<pre>';
//		print_r($this->view->projectcases);exit;
		$arrProject = $project->getprojectByproject_id($project_id);
		$this->view->project = $arrProject;
		
		//相关项目
		$arrKeys = explode(' ',$arrProject[0]['key_word']);
		foreach($arrKeys as $row){
			if(!empty($row)) $arrKeyWords[] = $row;
		}
		
		$projectrelateds = $project->getProjectRelated($arrKeyWords,9999,'');
		//总条数
		$pro_total = count($projectrelateds);

		//总页数
		$perpage = "10";
		$pro_pages = ceil($pro_total/$perpage);
		$pro_start = ($pro_page-1)*$perpage;
		$pro_end = $perpage;
		$this->view->pro_page = $pro_page;
		$this->view->pro_pages = $pro_pages;
		$this->view->pro_total = $pro_total;
		
		//print_r($arrKeyWords);
		$projectrelated = $project->getProjectRelated($arrKeyWords,$pro_page,$pro_end);
		foreach($projectrelated as $key=>$row){
			if ($row['project_id'] == $project_id) {
				unset($projectrelated[$key]);
				break;
			}
		}
		$this->view->projectrelated = $projectrelated;
		
		//新增pid>0
		$pid = $this->view->project[0]['pid'];
		if($pid>0){
			$p = $project->getprojectByproject_id($pid);
			$this->view->p_project_name = $p[0]['title'];
		}
		$teacher_id = $this->view->project[0]['teacher_id'];
		$student_id = $this->view->project[0]['student_id'];
		$class_id = $this->view->project[0]['class_id'];
		$teacher = $teacher->getteacherByteacher_id($teacher_id);
		if(count($teacher)=='0'){
			$this->view->teacher_name = '';
		}else{
			$this->view->teacher_name = $teacher[0]['name'];
		}
	
		$student = $student->getStudentBystudent_id($student_id);
		if(count($student)=='0'){
			 $this->view->student_name = '';
		}else{
			 $this->view->student_name = $student[0]['name'];
		}
	
		$class = $class->getclassByclass_id($class_id);
		if(count($class)=='0'){
			$this->view->class_name = '';
		}else{
			$this->view->class_name = $class[0]['name'];
		}
		//查询所有的comment和发表comment的用户名
		$count = $db->select_comment('','',$project_id,'1');
	
		//总条数
		$total = count($count);
		//总页数
		$perpage = "2";
		$pages = ceil($total/$perpage);
		$start = ($page-1)*$perpage;
		$end = $perpage;
		$this->view->page = $page;
		$this->view->pages = $pages;
		$this->view->total = $total;
	
		$this->view->comments = $db->select_comment($start,$end,$project_id,'1');
	
		//取案例
		$cases = $projectcase->getprojectcaseByproject_id($project_id);
		//取出所有的case_id放在一个数组里
		$array = array();
		for($i=0;$i<count($cases);$i++){
			$array[].=$cases[$i]['case_id'];
		}
		if(count($array)!=0){
			$ps_totoal = $project->getAllProjectInArray($array,9999,'');
		    $ps_total = count($ps_totoal);
	
			//总页数
			$perpage = "10";
			$ps_pages = ceil($ps_total/$perpage);
			$ps_start = ($ps_page-1)*$perpage;
			$ps_end = $perpage;
			$this->view->ps_page = $ps_page;
			$this->view->ps_pages = $ps_pages;
			$this->view->ps_total = $ps_total;
			$this->view->project_cases = $project->getAllProjectInArray($array,$ps_page,$ps_end);
		}
		$tag_current = $projecttag->getprojecttagByproject_id($project_id);
		$arr = array('0'=>'0');
		for($i=0;$i<count($tag_current);$i++){
			$arr[].=$tag_current[$i]['tag_id'];
		}
	   
		$this->view->tag_current = $tag->getAllTagInArray($arr);
	
		$time = time();
		$data = array(
			'op_name'=>'detail',
			'model_name'=>'project',
			'user_id'=>$_SESSION['user']['user_id'],
			'user_name'=>$_SESSION['user']['user_name'],
			'name'=>'查看项目详情',
			'create_time'=>$time
		);
		$query = $operation->insert($data);
		echo $this->view->render('project/detail.html');
	}

	public function updateAction(){
	    $filter=new Zend_Filter_StripTags();
	    $project = new Project();
	    $project_id=$filter->filter(($this->_request->getParam('project_id')));
	    $this->view->project = $project->getprojectByproject_id($project_id);
	    echo $this->view->render('project/update.html');
	}

	//删除项目
	public function deleteAction(){
		$filter=new Zend_Filter_StripTags();
		$project = new Project();
		$projectTag = new ProjectTag();
		$operation = new Operation();
		$project_id=$filter->filter(($this->_request->getParam('project_id')));
		$query = $project->delprojectByproject_id($project_id);

		if($query){
			$projectTag->delProjectTagByProject_id($project_id);
			$time = time();
			$data = array(
				'op_name'=>'delete',
				'model_name'=>'project',
				'user_id'=>$_SESSION['user']['user_id'],
				'user_name'=>$_SESSION['user']['user_name'],
				'name'=>'删除项目',
				'create_time'=>$time
			);
			$query = $operation->insert($data);
			echo "<script>window.location='list'</script>";
		}else{
			
		}
	}
	   
	public function hoverAction(){
		$filter = new Zend_Filter_StripTags();
		$project = new Project();
		$pid=$filter->filter(($this->_request->getParam('pid')));
		$search_name=$filter->filter(($this->_request->getParam('search_name')));
		$this->view->projects = $project->getAllProjects($pid,$search_name);
		echo $this->view->render('project/hover.html');
	}

	   public function fileAction(){
            $filter = new Zend_Filter_StripTags();
            $project = new Project();
            $projectfile = new Projectfile();
            $project_id=$filter->filter(($this->_request->getParam('project_id')));
            if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
                $summary=$this->_request->getPost('summary');

                $path= "public/files/project/".date("Ym",time())."/";//上传路径
		if(!file_exists($path))
                {
                   mkdir("$path", 0700);
                 }//END IF
                $path= "public/files/project/".date("Ym",time())."/".date("d",time())."/";//上传路径
                if(!file_exists($path))
                {
                  mkdir("$path", 0700);
                 }
                 $name=$_FILES["file_upload"]["name"];
                 $file1=GetID( ".".strtolower(substr($_FILES['file_upload']['name'], (strrpos($_FILES['file_upload']['name'], '.') + 1))));
                 $path = $path.$file1;
                  move_uploaded_file($_FILES["file_upload"]["tmp_name"],$path);


                  $time = time();
                  $array = array(
                      'project_id'=>$project_id,
                      'file_name'=>$name,
                      'summary'=>$summary,
                      'path'=>$path,
                      'create_time'=>$time,
                      'status'=>'0'
                  );
                $file_id = $projectfile->insert($array);
                if($file_id){
                    echo "<script>window.location='detail?project_id=".$project_id."'</script>";
                }else{
                    echo "<script>alert('Failure!');window.location='detail?project_id=".$project_id."'</script>";
                }

            }else{

                $this->view->project = $project->getprojectByproject_id($project_id);
				$this->view->projectfiles = $projectfile->getprojectfileByproject_id($project_id);
            }


            echo $this->view->render('project/file.html');
       }

 //删除项目文件      
       public function filedelAction(){
          	$filter = new Zend_Filter_StripTags();
            $projectfile = new Projectfile();
            $project_id=$filter->filter($this->_request->getParam('project_id'));
            $file_id=$filter->filter($this->_request->getParam('file_id'));
            $result = $projectfile->delprojectfileByfile_id($file_id);
            if( $result ){
            	echo "<script>window.location='detail?project_id=".$project_id."'</script>";
            }
       }
       
//为项目添加案例
	   public function caseaddAction(){
            $filter=new Zend_Filter_StripTags();
            $project = new Project();
            $projectcase = new Projectcase();
                if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
                    $project_id=$filter->filter(($this->_request->getPost('project_id')));
                    $case_id=$_POST['case_id'];

                        $count = count($case_id);
                  if($count!=0){
                        for($i=1;$i<=$count;$i++){
                            $data=array(
                              'project_id'=>$project_id,
                              'case_id'=>$case_id[$i-1]
                            );
                            $projectcase->insert($data);
                            unset($data);
                        }
                       echo "<script>window.location='detail?project_id=".$project_id."'</script>";
                   }
                }else{
                        $this->view->project = $project->getprojectByproject_id($project_id);
                     //去的所有的项目id，然后去除已经存在的和该项目本身
                        $cases = $projectcase->getprojectcaseByproject_id($project_id);
                        //取出所有的case_id放在一个数组里
                        $array = array();
                           for($i=0;$i<count($cases);$i++){
                                           $array[].=$cases[$i]['case_id'];
                                       }
                        $projects = $project->getAllProjects('','');
                        $data = array();
                           for($i=0;$i<count($projects);$i++){
                                           $data[].=$projects[$i]['case_id'];
                                       }
                        $array[].=$project_id;
                        $projects = $project->getAllProjects('','');
                        $data = array();
                           for($i=0;$i<count($projects);$i++){
                                           $data[].=$projects[$i]['project_id'];
                                       }
                        $pros = merger($array, $data);
                        $this->view->projects = $project->getAllProjectInArray($pros);
                }
            echo $this->view->render('project/case.html');
       }
//根据项目id，取出该项目所有案例
      public function caseAction(){
            $filter=new Zend_Filter_StripTags();
            $project = new Project();
            $projectcase = new Projectcase();
            $project_id=$filter->filter(($this->_request->getParam('project_id')));

            $cases = $projectcase->getprojectcaseByproject_id($project_id);
            //取出所有的case_id放在一个数组里
            $array = array();
               for($i=0;$i<count($cases);$i++){
                               $array[].=$cases[$i]['case_id'];
                           }
            if(count($array)!=0){
               $this->view->project_cases = $project->getAllProjectInArray($array,9999,'');
            }
          //去的所有的项目id，然后去除已经存在的和该项目本身
            $array[].=$project_id;
            $projects = $project->getAllProjects('','');
            $data = array();
               for($i=0;$i<count($projects);$i++){
                               $data[].=$projects[$i]['project_id'];
                           }
            $pros = merger($array, $data);

            $this->view->projects = $project->getAllProjectInArray($pros,9999,'');
            $this->view->project = $project->getprojectByproject_id($project_id);
            echo $this->view->render('project/case.html');
      }

//删除案例
public function casedelAction(){
            $filter=new Zend_Filter_StripTags();
            $projectcase = new Projectcase();
            $project_id=$filter->filter(($this->_request->getParam('project_id')));
            $case_id=$filter->filter(($this->_request->getParam('case_id')));
            $query = $projectcase->delprojectcaseByprojectid($project_id, $case_id);
            if($query){
                echo "<script>window.location='case?project_id=".$project_id."'</script>";
            }
 }

 //删除标签
public function tagdelAction(){
            $filter=new Zend_Filter_StripTags();
            $projecttag = new ProjectTag();
            $project_id=$filter->filter(($this->_request->getParam('project_id')));
            $tag_id=$filter->filter(($this->_request->getParam('tag_id')));
            $query = $projecttag->delprojecttagByprojectid($project_id, $tag_id);
            if($query){
                echo "<script>window.location='tag?project_id=".$project_id."'</script>";
            }
 }

 public function tagAction(){
            $filter=new Zend_Filter_StripTags();
            $projecttag = new ProjectTag();
            $project = new Project();
            $tag = new Tag();
            $project_id=$filter->filter(($this->_request->getParam('project_id')));
             if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
                    $project_id=$filter->filter(($this->_request->getPost('project_id')));
                    $tag_id=$_POST['tag_id'];

                    $count = count($tag_id);
                      if($count!=0){
                            for($i=1;$i<=$count;$i++){
                                $data=array(
                                  'project_id'=>$project_id,
                                  'tag_id'=>$tag_id[$i-1]
                                );
                                $projecttag->insert($data);
                                unset($data);
                            }
                           echo "<script>window.location='detail?project_id=".$project_id."'</script>";
                       }
                }else{
                    $this->view->project = $project->getprojectByproject_id($project_id);
                    $tag_current = $projecttag->getprojecttagByproject_id($project_id);
                    $type=$filter->filter(($this->_request->getParam('type')));
                    $search=$filter->filter(($this->_request->getParam('search')));
                    $arr = array('0'=>'0');
                    for($i=0;$i<count($tag_current);$i++){
                        $arr[].=$tag_current[$i]['tag_id'];
                    }
                    $this->view->tag_current = $tag->getAllTagInArray($arr);
                    if(!empty($type)){
                        $this->view->tags = $tag->getAllTags('','','','');
                    }else if(!empty($search)){
                        $this->view->tags = $tag->getAllTags('','', $search,'');

                    }else{
                        $project = $this->view->project;
                        $keys = $project[0]['key_word'];

                        $this->view->tags = $tag->getAllTags('','','', $keys);
                    }

                }
            echo $this->view->render('project/tag.html');
 }


	public function editexcellenceAction(){
    	$filter=new Zend_Filter_StripTags();
    	$project = new Project();
		$operation = new Operation();
    	$project_id=$filter->filter(($this->_request->getParam('project_id')));

    	if(strtolower($_SERVER['REQUEST_METHOD'])=='get' && $project_id>0){
			$excellence=$filter->filter(($this->_request->getParam('excellence')));
			$update_time = time();
			$data = array(
				'excellence'=>$excellence,
				'update_time'=>$update_time,
				'user_id'=>$_SESSION['user']['user_id'],
			);
			$project->updateprojectByproject_id($data, $project_id);
            $time = time();
			$data = array(
				'op_name'=>'edit',
				'model_name'=>'project',
				'user_id'=>$_SESSION['user']['user_id'],
				'user_name'=>$_SESSION['user']['user_name'],
				'name'=>'修改项目',
				'create_time'=>$time
			);
			$query = $operation->insert($data);
            echo "<script>window.history.go(-1);</script>";
		}else{
			echo "<script>alert('Failure!');window.history(-1)";
		}
	}
	
	public function typestatAction(){
		$filter=new Zend_Filter_StripTags();
		$year=$filter->filter(($this->_request->getParam('year')));
		$category=$filter->filter(($this->_request->getParam('category')));
		$page=$filter->filter(($this->_request->getParam('page')));
		$page = !empty($page)?$page:1;
		$project = new Project();
		$student = new Student();
		$company = new Company();
		$projecttag = new ProjectTag();
		$tag = new Tag();
		$time1 = strtotime($year.'-01-01');
		$time2 = strtotime(($year+1).'-01-01');
		$arrProject = $project->getProjectByTimeType($time1,$time2,$category);
		$total = count($arrProject);
		$perpage = 10;
		$arrProject = array_slice($arrProject,($page-1)*$perpage,$perpage);
		foreach($arrProject as $key=>$row){
			$arrStudent = !empty($row['student_id'])?$student->getStudentBystudent_id($row['student_id']):array();
			$arrCompany = !empty($arrStudent[0]['company_id'])?$company->getCompanyBycompany_id($arrStudent[0]['company_id']):array();
			$arrTag = $projecttag->getprojecttagByproject_id($row['project_id']);
			$arrTagName = array();
			if (!empty($arrTag)) {
				foreach($arrTag as $tag_key=>$tag_row){
					$arrTagInfo = $tag->gettagBytag_id($tag_row['tag_id']);
					$arrTagName[] = $arrTagInfo[0]['name'];
				}
			}
			$arrProject[$key]['student_name'] = $arrStudent[0]['name'];
			$arrProject[$key]['company_name'] = $arrCompany[0]['name'];
			$arrProject[$key]['tag_name'] = implode('，',$arrTagName);
		}
		$this->view->arrProject = $arrProject;
		
		$pages = ceil($total/$perpage);
		$this->view->page = $page;
		$this->view->pages = $pages;
		$this->view->total = $total;
		
		echo $this->view->render('project/typestat.html');
	}
	

	public function barsAction(){
		$filter = new Zend_Filter_StripTags();
		$project = new Project();
		$arrDate = getdate();
		$year = $arrDate['year']+1;
		$time = strtotime($year.'-01-01');
		$arrTime = array();
		$project_type = $this->view->conf ->projectType;
		
		for ($i=0;$i<8;$i++) {
			$arrTime[] = array(strtotime(($year-1).'-01-01'), strtotime(($year).'-01-01'));
			$year--;
			$arrYear[] = $year;
			$arrProjectType[] = array(0,0,0,0);
		}
		//$arrYear = array_reverse($arrYear);
		foreach($arrYear as $row){
			$arrYearShow[] = strval($row);
		}
		$arrProject = array();
		foreach($arrTime as $key=>$row){
			$arrProject = $project->getProjectByTime($row[0] ,$row[1]);
			foreach($arrProject as $k=>$v){
				$arrProjectType[$key][$arrProject[$k]['category']]++;
			}
		}
		$count = count($arrProjectType);
		for($i=0;$i<$count;$i++){
			foreach($arrProjectType[$i] as $key=>$row){
				$arrTypeNum[$key][] = $row;
			}
		}
		require_once('./public/chart/php-ofc-library/open-flash-chart.php');
		
		$title = new title( date("项目数量分布") );

		foreach ($project_type as $v=>$l){
			$arr[] = $arrTypeNum[$v ];
			$s[] = max($arrTypeNum[$v ]);
		}
		 
		$intMax = max($s);
		$y_num = ($intMax>=10)?ceil($intMax/10)*10:10;
		$ss = array();
				$y = new y_axis(); 
		$y->set_range( 0, $y_num, $y_num/10 );
		
		$x = new x_axis();
		$x->set_labels_from_array( $arrYearShow );
		
		$chart = new open_flash_chart();
		$chart->set_title( $title );
		
		foreach($project_type as $k=>$val){        
					$bar =  new bar_glass();
					$bar->set_values( $arr[$k] );
					$bar->set_colour(rand_color());
					$bar->set_on_show(new bar_on_show('pop-up',0.5,0.2));
					$bar->set_tooltip( $val.'：#val#' );			
					$chart->add_element( $bar );
					$ss[] = $bar;
		}
		$chart->set_y_axis( $y );
		$chart->set_x_axis( $x );
		
		echo $chart->toPrettyString();
	}
	
	public function bars1Action(){
		$filter = new Zend_Filter_StripTags();
		$project = new Project();
		$arrDate = getdate();
		$year = $arrDate['year']+1;
		$time = strtotime($year.'-01-01');
		$arrTime = array();
		$project_type = $this->view->conf ->projectType;
		for ($i=0;$i<8;$i++) {
			$arrTime[] = array(strtotime(($year-1).'-01-01'), strtotime(($year).'-01-01'));
			$year--;
			$arrYear[] = $year;
			$arrProjectType[] = array(0,0,0,0);
			$arrProjectIncome[] = array(0,0,0,0);
		}
		//$arrYear = array_reverse($arrYear);
		foreach($arrYear as $row){
			$arrYearShow[] = strval($row);
		}
		$arrProject = array();
		foreach($arrTime as $key=>$row){
			$arrProject = $project->getProjectByTime($row[0] ,$row[1]);
			foreach($arrProject as $k=>$v){
				$arrProjectType[$key][$arrProject[$k]['category']]++;
				$arrProjectIncome[$key][$arrProject[$k]['category']]+=$v['income'];
			}
		}
		$count = count($arrProjectType);
		for($i=0;$i<$count;$i++){
			foreach($arrProjectIncome[$i] as $key=>$row){
				$arrIncomeNum[$key][] = $row;
			}
		}
		require_once('./public/chart/php-ofc-library/open-flash-chart.php');
		
		$title = new title( date("项目结余分布") );
		
		foreach ($project_type as $v=>$l){
			$arr[] = $arrIncomeNum[$v ];
			$s[] = max($arrIncomeNum[$v ]);
		}
		 
		$intMax = max($s);
		$y_num = ($intMax>=10)?ceil($intMax/10)*10:10;
		$ss = array();
				$y = new y_axis(); 
		$y->set_range( 0, $y_num, $y_num/10 );
		
		$x = new x_axis();
		$x->set_labels_from_array( $arrYearShow );
		
		$chart = new open_flash_chart();
		$chart->set_title( $title );
		
		foreach($project_type as $k=>$val){        
					$bar =  new bar_glass();
					$bar->set_values( $arr[$k] );
					$bar->set_colour(rand_color());
					$bar->set_on_show(new bar_on_show('pop-up',0.5,0.2));
					$bar->set_tooltip( $val.'：#val#' );			
					$chart->add_element( $bar );
					$ss[] = $bar;
		}
		$chart->set_y_axis( $y );
		$chart->set_x_axis( $x );
		
		echo $chart->toPrettyString();
	}
	
	public function bars2Action(){
		$filter = new Zend_Filter_StripTags();
		$project = new Project();
		$arrDate = getdate();
		$year = $arrDate['year']+1;
		$time = strtotime($year.'-01-01');
		$arrTime = array();
		for ($i=0;$i<8;$i++) {
			$arrTime[] = array(strtotime(($year-1).'-01-01'), strtotime(($year).'-01-01'));
			$year--;
			$arrYear[] = $year;
			$arrProjectKind[] = array(0,0,0);
		}
		//$arrYear = array_reverse($arrYear);
		foreach($arrYear as $row){
			$arrYearShow[] = strval($row);
		}
		$arrProject = array();
		foreach($arrTime as $key=>$row){
			$arrProject = $project->getProjectByTime($row[0] ,$row[1]);
			foreach($arrProject as $k=>$v){
				$arrProjectKind[$key][$arrProject[$k]['kind']]++;
			}
		}
		$count = count($arrProjectKind);
		for($i=0;$i<$count;$i++){
			foreach($arrProjectKind[$i] as $key=>$row){
				$arrKindNum[$key][] = $row;
			}
		}
		require_once('./public/chart/php-ofc-library/open-flash-chart.php');
		
		$title = new title( date("项目类别分布（设计、制造、职能）") );
		
		$arr1 = $arrKindNum[0];
		$arr2 = $arrKindNum[1];
		$arr3 = $arrKindNum[2];
		$arrMax = array(max($arr1),max($arr2),max($arr3));
		$intMax = max($arrMax);
		$y_num = ($intMax>=10)?ceil($intMax/10)*10:10;
		
		$bar1 = new bar_glass();
		$bar1->set_values( $arr1 );
		$bar1->set_colour('#006600');
		$bar1->set_on_show(new bar_on_show('pop-up',0.5,0.2));
		$bar1->set_tooltip( '设计：#val#' );
		
		$bar2 = new bar_glass();
		$bar2->set_values( $arr2 );
		$bar2->set_colour('#000000');
		$bar2->set_on_show(new bar_on_show('pop-up',0.5,0.2));
		$bar2->set_tooltip( '制造：#val#' );
		
		$bar3 = new bar_glass();
		$bar3->set_values( $arr3 );
		$bar3->set_colour('#0000ff');
		$bar3->set_on_show(new bar_on_show('pop-up',0.5,0.2));
		$bar3->set_tooltip( '职能：#val#' );
		
		$y = new y_axis(); 
		$y->set_range( 0, $y_num, $y_num/10 );
		
		$x = new x_axis();
		$x->set_labels_from_array( $arrYearShow );
		
		$chart = new open_flash_chart();
		$chart->set_title( $title );
		$chart->add_element( $bar1 );
		$chart->add_element( $bar2 );
		$chart->add_element( $bar3 );
		$chart->set_y_axis( $y );
		$chart->set_x_axis( $x );
		
		echo $chart->toPrettyString();
	}
	
	public function linegbAction(){
		$project = new Project();
		$arrDate = getdate();
		$year = $arrDate['year']+1;
		$time = strtotime($year.'-01-01');
		$arrTime = array();
		for ($i=0;$i<8;$i++) {
			$arrTime[] = array(strtotime(($year-1).'-01-01'), strtotime(($year).'-01-01'));
			$year--;
			$arrYear[] = $year;
			$arrProjectType[] = array(0,0,0,0);
		}
		//$arrYear = array_reverse($arrYear);
		foreach($arrYear as $row){
			$arrYearShow[] = strval($row);
		}
		$arrProject = array();
		foreach($arrTime as $key=>$row){
			$arrProject = $project->getProjectByTime($row[0] ,$row[1]);
			foreach($arrProject as $k=>$v){
				$arrProjectType[$key][$arrProject[$k]['category']]++;
			}
		}
		$count = count($arrProjectType);
		for($i=0;$i<$count;$i++){
			foreach($arrProjectType[$i] as $key=>$row){
				$arrTypeNum[$key][] = $row;
			}
		}
		
		include './public/chart/php-ofc-library/open-flash-chart.php';
		$arr1 = $arrTypeNum[0];
		$intMax = max($arr1);
		$y_num = ($intMax>=10)?floor($intMax/10)*10:10;
		
		$data_1 = $arr1;
		
		$default_dot = new dot();
		$default_dot->size(5)->colour('#006600');
		
		$line_dot = new line();
		$line_dot->set_default_dot_style($default_dot);
		$line_dot->set_width( 4 );
		$line_dot->set_colour( '#006600' );
		$line_dot->set_values( $data_1 );
		$line_dot->set_key( "GB", 10 );
		
		$y = new y_axis();
		$y->set_range( 0, $y_num, $y_num/10 ); 
		
		$x = new x_axis();
		$x->set_labels_from_array( $arrYearShow );
		
		$chart = new open_flash_chart();
		$chart->set_title( new title( 'GB project' ) );
		$chart->set_y_axis( $y );
		$chart->set_x_axis( $x );

		$chart->add_element( $line_dot );
		
		echo $chart->toPrettyString();
	}
	
	public function linebbAction(){
		$project = new Project();
		$arrDate = getdate();
		$year = $arrDate['year']+1;
		$time = strtotime($year.'-01-01');
		$arrTime = array();
		for ($i=0;$i<8;$i++) {
			$arrTime[] = array(strtotime(($year-1).'-01-01'), strtotime(($year).'-01-01'));
			$year--;
			$arrYear[] = $year;
			$arrProjectType[] = array(0,0,0,0);
		}
		//$arrYear = array_reverse($arrYear);
		foreach($arrYear as $row){
			$arrYearShow[] = strval($row);
		}
		$arrProject = array();
		foreach($arrTime as $key=>$row){
			$arrProject = $project->getProjectByTime($row[0] ,$row[1]);
			foreach($arrProject as $k=>$v){
				$arrProjectType[$key][$arrProject[$k]['category']]++;
			}
		}
		$count = count($arrProjectType);
		for($i=0;$i<$count;$i++){
			foreach($arrProjectType[$i] as $key=>$row){
				$arrTypeNum[$key][] = $row;
			}
		}
		
		include './public/chart/php-ofc-library/open-flash-chart.php';
		
		$arr1 = $arrTypeNum[1];
		$intMax = max($arr1);
		$y_num = ($intMax>=10)?floor($intMax/10)*10:10;
		
		$data_1 = $arr1;
		
		$default_dot = new dot();
		$default_dot->size(5)->colour('#000000');
		
		$line_dot = new line();
		$line_dot->set_default_dot_style($default_dot);
		$line_dot->set_width( 4 );
		$line_dot->set_colour( '#000000' );
		$line_dot->set_values( $data_1 );
		$line_dot->set_key( "BB", 10 );
		
		$y = new y_axis();
		$y->set_range( 0, $y_num, $y_num/10 ); 
		
		$x = new x_axis();
		$x->set_labels_from_array( $arrYearShow );
		
		$chart = new open_flash_chart();
		$chart->set_title( new title( 'BB project' ) );
		$chart->set_y_axis( $y );
		$chart->set_x_axis( $x );
		
		$chart->add_element( $line_dot );
		
		echo $chart->toPrettyString();
	}
	
	public function linechAction(){
		$project = new Project();
		$arrDate = getdate();
		$year = $arrDate['year']+1;
		$time = strtotime($year.'-01-01');
		$arrTime = array();
		for ($i=0;$i<8;$i++) {
			$arrTime[] = array(strtotime(($year-1).'-01-01'), strtotime(($year).'-01-01'));
			$year--;
			$arrYear[] = $year;
			$arrProjectType[] = array(0,0,0,0);
		}
		//$arrYear = array_reverse($arrYear);
		foreach($arrYear as $row){
			$arrYearShow[] = strval($row);
		}
		$arrProject = array();
		foreach($arrTime as $key=>$row){
			$arrProject = $project->getProjectByTime($row[0] ,$row[1]);
			foreach($arrProject as $k=>$v){
				$arrProjectType[$key][$arrProject[$k]['category']]++;
			}
		}
		$count = count($arrProjectType);
		for($i=0;$i<$count;$i++){
			foreach($arrProjectType[$i] as $key=>$row){
				$arrTypeNum[$key][] = $row;
			}
		}
		
		include './public/chart/php-ofc-library/open-flash-chart.php';
		
		$arr1 = $arrTypeNum[2];
		$intMax = max($arr1);

		srand((double)microtime()*1000000);
		
		$data_1 = $arr1;
		
		$default_dot = new dot();
		$default_dot->size(5)->colour('#0000ff');
		
		$line_dot = new line();
		$line_dot->set_default_dot_style($default_dot);
		$line_dot->set_width( 4 );
		$line_dot->set_colour( '#0000ff' );
		$line_dot->set_values( $data_1 );
		$line_dot->set_key( "CH", 10 );
		
		$y = new y_axis();
		$y->set_range( 0, $y_num, $y_num/10 ); 
		
		$x = new x_axis();
		$x->set_labels_from_array( $arrYearShow );
		
		$chart = new open_flash_chart();
		$chart->set_title( new title( 'CH project' ) );
		$chart->set_y_axis( $y );
		$chart->set_x_axis( $x );
		
		$chart->add_element( $line_dot );
		
		echo $chart->toPrettyString();
	}
	
	public function linettAction(){
		$project = new Project();
		$arrDate = getdate();
		$year = $arrDate['year']+1;
		$time = strtotime($year.'-01-01');
		$arrTime = array();
		for ($i=0;$i<8;$i++) {
			$arrTime[] = array(strtotime(($year-1).'-01-01'), strtotime(($year).'-01-01'));
			$year--;
			$arrYear[] = $year;
			$arrProjectType[] = array(0,0,0,0);
		}
		//$arrYear = array_reverse($arrYear);
		foreach($arrYear as $row){
			$arrYearShow[] = strval($row);
		}
		$arrProject = array();
		foreach($arrTime as $key=>$row){

			$arrProject = $project->getProjectByTime($row[0] ,$row[1]);
			foreach($arrProject as $k=>$v){
				$arrProjectType[$key][$arrProject[$k]['category']]++;
			}
		}
		$count = count($arrProjectType);
		for($i=0;$i<$count;$i++){
			foreach($arrProjectType[$i] as $key=>$row){
				$arrTypeNum[$key][] = $row;
			}
		}
		
		include './public/chart/php-ofc-library/open-flash-chart.php';
		
		$arr1 = $arrTypeNum[3];
		$intMax = max($arr1);
		$y_num = ($intMax>=10)?floor($intMax/10)*10:10;
		
		$data_1 = $arr1;
		
		$default_dot = new dot();
		$default_dot->size(5)->colour('#ff00ff');
		
		$line_dot = new line();
		$line_dot->set_default_dot_style($default_dot);
		$line_dot->set_width( 4 );
		$line_dot->set_colour( '#ff00ff' );
		$line_dot->set_values( $data_1 );
		$line_dot->set_key( "TT", 10 );
		
		$y = new y_axis();
		$y->set_range( 0, $y_num, $y_num/10 ); 
		
		$x = new x_axis();
		$x->set_labels_from_array( $arrYearShow );
		
		$chart = new open_flash_chart();
		$chart->set_title( new title( 'TT project' ) );
		$chart->set_y_axis( $y );
		$chart->set_x_axis( $x );

		$chart->add_element( $line_dot );
		
		echo $chart->toPrettyString();
	}
	
	public function pie1Action(){
		$filter = new Zend_Filter_StripTags();
		$project = new Project();
		$arrDate = getdate();
		$year = $arrDate['year']+1;
		$time = strtotime($year.'-01-01');
		$arrTime = array();
		for ($i=0;$i<1;$i++) {
			$arrTime[] = array(strtotime(($year-1).'-01-01'), strtotime(($year).'-01-01'));
			$year--;
			$arrYear[] = $year;
			$arrProjectType[] = array(0,0,0,0);
		}
		//$arrYear = array_reverse($arrYear);
		foreach($arrYear as $row){
			$arrYearShow[] = strval($row);
		}
		$arrProject = array();
		foreach($arrTime as $key=>$row){
			$arrProject = $project->getProjectByTime($row[0] ,$row[1]);
			foreach($arrProject as $k=>$v){
				$arrProjectType[$key][$arrProject[$k]['category']]++;
			}
		}
		$count = count($arrProjectType);
		for($i=0;$i<$count;$i++){
			foreach($arrProjectType[$i] as $key=>$row){
				$arrTypeNum[$key][] = $row;
			}
		}
		
		require_once('./public/chart/php-ofc-library/open-flash-chart.php');
		
		
		$d = array();
		$d[] = new pie_value($arrTypeNum[0][0], "GB");
		$d[] = new pie_value($arrTypeNum[1][0], "BB");
		$d[] = new pie_value($arrTypeNum[2][0], "CH");
		$d[] = new pie_value($arrTypeNum[3][0], "TT");

		
		$pie = new pie();
		$pie->alpha(0.5);
    	$pie->add_animation( new pie_fade() );
    	$pie->add_animation( new pie_bounce(4) );
		$pie->set_animate( true );
		$pie->set_label_colour( '#432BAF' );
		$pie->set_alpha( 0.75 );
		$pie->set_tooltip( '#label#<br>#val# (#percent#)' );
		$pie->set_colours(
			array(
            '#339900',
            '#660066',
            '#1F8FA1',
            '#ff0033'
        ) );
		
		$pie->set_values( $d );
		$title = new title( $year.'年项目数量分布' );
		$chart = new open_flash_chart();
		$chart->set_title( $title );
		$chart->add_element( $pie );
		
		echo $chart->toPrettyString();
	}
	
	public function pie2Action(){
		$filter = new Zend_Filter_StripTags();
		$project = new Project();
		$arrDate = getdate();
		$year = $arrDate['year']+1;
		$time = strtotime($year.'-01-01');
		$arrTime = array();
		for ($i=0;$i<1;$i++) {
			$arrTime[] = array(strtotime(($year-1).'-01-01'), strtotime(($year).'-01-01'));
			$year--;
			$arrYear[] = $year;
			$arrProjectType[] = array(0,0,0,0);
		}
		//$arrYear = array_reverse($arrYear);
		foreach($arrYear as $row){
			$arrYearShow[] = strval($row);
		}
		$arrProject = array();
		foreach($arrTime as $key=>$row){
			$arrProject = $project->getProjectByTime($row[0] ,$row[1]);
			foreach($arrProject as $k=>$v){
				$arrProjectIncome[$key][$arrProject[$k]['category']]+=$v['income'];
			}
		}
		$count = count($arrProjectIncome);
		for($i=0;$i<$count;$i++){
			foreach($arrProjectIncome[$i] as $key=>$row){
				$arrIncomeNum[$key][] = $row;
			}
		}
		
		require_once('./public/chart/php-ofc-library/open-flash-chart.php');
		
		
		$d = array();
		$d[] = new pie_value($arrIncomeNum[0][0], "GB");
		$d[] = new pie_value($arrIncomeNum[1][0], "BB");
		$d[] = new pie_value($arrIncomeNum[2][0], "CH");
		$d[] = new pie_value($arrIncomeNum[3][0], "TT");

		
		$pie = new pie();
		$pie->alpha(0.5);
    	$pie->add_animation( new pie_fade() );
    	$pie->add_animation( new pie_bounce(4) );
		$pie->set_animate( true );
		$pie->set_label_colour( '#432BAF' );
		$pie->set_alpha( 0.75 );
		$pie->set_tooltip( '#label#<br>#val# (#percent#)' );
		$pie->set_colours(
			array(
            '#339900',
            '#660066',
            '#1F8FA1',
            '#ff0033'
        ) );
		
		$pie->set_values( $d );
		$title = new title( $year.'项目收益分布' );
		$chart = new open_flash_chart();
		$chart->set_title( $title );
		$chart->add_element( $pie );
		
		echo $chart->toPrettyString();
	}
}
?>
